<template>
  <el-card class="notice-card" shadow="hover">
    <!-- 顶部信息行 -->
    <div class="card-header">
      <div class="header-info">
        <span class="id-tag">#{{ notice.id }}</span>
        <!-- 显示通知类型 -->
        <span class="type-badge" :class="getTypeClass(notice.type)">{{ getTypeName(notice.type) }}</span>
        <span class="user-id">用户ID: {{ notice.userId }}</span>
        <span class="time">{{ notice.time }}</span>
      </div>
    </div>

    <!-- 中间内容区域 -->
    <div class="card-content">
      <p class="content-text">{{ notice.text }}</p>
    </div>

    <!-- 底部媒体和操作区域 -->
    <div class="card-footer">
      <div class="media-url" v-if="notice.url">
        <el-link :href="notice.url" type="primary" target="_blank">查看媒体资源</el-link>
      </div>
      <div class="actions">
        <el-button size="small" @click="handleViewDetail">查看详情</el-button>
        <el-button size="small" type="danger" @click="handleDelete">删除</el-button>
      </div>
    </div>
  </el-card>
</template>

<script setup lang="ts">
import { defineProps, defineEmits } from 'vue'

const props = defineProps({
  notice: {
    type: Object,
    required: true
  }
})

const emits = defineEmits(['delete', 'viewDetail'])

// 类型名称映射
const getTypeName = (type: string) => {
  const map = {
    'like': '点赞',
    'comment': '评论',
    'collection': '收藏',
    'follow': '关注',
    'message': '私信'
  }
  return map[type] || type
}

// 类型样式映射
const getTypeClass = (type: string) => {
  const map = {
    'like': 'bg-blue',
    'comment': 'bg-green',
    'collection': 'bg-orange',
    'follow': 'bg-purple',
    'message': 'bg-red'
  }
  return map[type] || 'bg-gray'
}

const handleDelete = () => {
  emits('delete', props.notice.id)
}

const handleViewDetail = () => {
  emits('viewDetail', props.notice)
}
</script>

<style scoped>
.notice-card {
  border-color: #2c2c2c;
  color: #e0e0e0;
}

.card-header {
  padding: 12px 16px;
}

.header-info {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 14px;
}

.id-tag {
  background-color: #333;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 500;
}

/* 新增类型标签样式 */
.type-badge {
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 500;
  font-size: 12px;
}

.bg-blue { background-color: #409eff; }
.bg-green { background-color: #67c23a; }
.bg-orange { background-color: #e6a23c; }
.bg-purple { background-color: #909399; }
.bg-red { background-color: #f56c6c; }
.bg-gray { background-color: #333; }

.card-content {
  padding: 16px;
}

.content-text {
  margin: 0;
  font-size: 16px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
}

.media-url {
  font-size: 14px;
}

.actions {
  display: flex;
  gap: 8px;
}
</style>